package com.me.mvc.controller.clients;

import javax.ws.rs.GET;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import com.me.mvc.model.ModelUtils;
import com.me.mvc.model.entity.Client;

import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Roman Uholnikov
 */
@RestController
public class ClientsAll {

    @GET
    @RequestMapping(value = "/clients/{clientId}/rest.json", method = RequestMethod.GET)
    @Produces({MediaType.APPLICATION_JSON})
    public Client getClientJson(ModelMap model, @PathVariable("clientId") Integer clientId) {
        model.addAttribute("client", ModelUtils.clientMap.get(clientId));
        return ModelUtils.clientMap.get(clientId);
    }

    @GET
    @RequestMapping(value = "/clients/{clientId}/rest.xml", method = RequestMethod.GET)
    @Produces({MediaType.APPLICATION_XML})
    public Client getClientXml(ModelMap model, @PathVariable("clientId") Integer clientId) {
        model.addAttribute("client", ModelUtils.clientMap.get(clientId));
        return ModelUtils.clientMap.get(clientId);
    }

    @GET
    @RequestMapping(value = "/clients/{clientId}/rest.atom", method = RequestMethod.GET)
    @Produces({MediaType.APPLICATION_ATOM_XML})
    public Client getClientAtom(ModelMap model, @PathVariable("clientId") Integer clientId) {
        model.addAttribute("client", ModelUtils.clientMap.get(clientId));
        return ModelUtils.clientMap.get(clientId);
    }

    @GET
    @RequestMapping(value = "/clients/{clientId}/rest.rss", method = RequestMethod.GET)
    @Produces({"application/rss+xml"})
    public Client getClientRss(ModelMap model, @PathVariable("clientId") Integer clientId) {
        model.addAttribute("client", ModelUtils.clientMap.get(clientId));
        return ModelUtils.clientMap.get(clientId);
    }

    @GET
    @RequestMapping(value = "/clients/{clientId}/rest", method = RequestMethod.GET)
    @Produces({"application/json", "application/xml"})
    public Client getClientCustom(ModelMap model, @PathVariable("clientId") Integer clientId) {
        model.addAttribute("client", ModelUtils.clientMap.get(clientId));
        return ModelUtils.clientMap.get(clientId);
    }
}
